/**
 * 
 */
package cn.edu.tyu.finance.entity.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import cn.edu.tyu.finance.entity.domain.Users;
import cn.edu.tyu.finance.util.DbUtil;

/**
 * @author WangAnRui
 *
 */
public class UserDaoImpl {
	public int addUser(Users users) throws SQLException {
//		1、获取到数据库连接
		Connection conn = DbUtil.getConnection();
//		2、编写sql语句
		String sql = "insert into users values(?,?,?)";
//		3、获取语句的执行者
		PreparedStatement ps = conn.prepareStatement(sql);
//	 	4、设置参数并赋值
		ps.setString(1, users.getUserid());
		ps.setString(2, users.getUsername());
		ps.setString(3, users.getUserpsw());
//		5、执行sql语句，返回影响的行数
		int res = ps.executeUpdate();
//		6、释放数据库的连接
		DbUtil.backConn(conn, ps, null);
		return res;
	}
	public static void main(String[] args) throws SQLException {
		UserDaoImpl userDao = new UserDaoImpl();
		Users users = new Users();
		users.setUserid("3");
		users.setUsername("lq");
		users.setUserpsw("123456");
		int res = userDao.addUser(users);
		System.out.println("res="+res);
	}
}
